import { defineStore } from 'pinia';
import { ref } from 'vue';

// 初始化状态
const doorState = {
	token: '',
	unionToken: '',
	params: { roomId: 3855326, doorId: 473146, openType: 2, openPage: 1, content: { roomNumber: '0401', unitNo: '005', buildingNo: '042', depName: '新造社区' } }
};

export const doorStore = defineStore(
	'door',
	() => {
		const doorInfo = ref({ ...doorState });
		// 设置token
		const setToken = (key: 'token' | 'unionToken', val: string) => {
			doorInfo.value[key] = val;
			if (key === 'unionToken') {
				doorInfo.value.token = '';
			}
		};

		const getParams = () => {
			return doorInfo.value.params;
		};
		const getToken = () => {
			return doorInfo.value.token;
		};

		return {
			doorInfo,
			setToken,
			getParams,
			getToken
		};
	},
	{
		persist: true
	}
);
